package mashuaiproject.mashuaiproject.mapper;

import mashuaiproject.mashuaiproject.model.Save;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SaveQuesionMapper {

    @Select("select creator from quesions where id=#{quesionId}")
    Integer selectById(@Param("quesionId") Integer quesionId);

    @Insert("insert into save(user_id,father_id,quesion_id,gmt_create)values(" +
            "#{user_id},#{father_id},#{quesion_id},#{gmt_create}) ")
    Integer insertSave(Save save);

    @Update("update quesions set like_count=like_count+1 where id=#{quesionId}")
    Integer upateLikeCOunt(@Param("quesionId") Integer quesionId);

    @Select("select like_count from quesions where id=#{quesionId}")
    Integer selectLike(@Param("quesionId") Integer quesionId);

    @Select("select *from save where quesion_id=#{quesion_id} and user_id=#{userId}")
    Save selectUserId(@Param("quesion_id") Integer quesionId,@Param("userId")Integer userId);

    @Select("select *from save where user_id=#{userId} limit #{offset},#{size}")
    List<Save> selectOneSave(@Param("userId") Integer id,@Param("offset")Integer offset,@Param("size")Integer size);
    @Select("select count(1) from save where user_id=#{userId}")
    Integer selectTotul(@Param("userId") Integer id);

    @Delete("delete from save where user_id=#{user_id} and quesion_id=#{quesion_id}")
    int delSaves(@Param("user_id") Integer id, @Param("quesion_id") Integer del);

}
